package com.game.web.controller.game;

import com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.core.page.TableDataInfo;
import com.game.common.enums.BusinessType;
import com.game.common.utils.poi.ExcelUtil;
import com.game.system.domain.game.GameLog;
import com.game.system.service.IGameLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 游戏日志Controller
 *
 * @author Mr.Liu
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/game/log")
public class GameLogController extends BaseController
{
    @Autowired
    private IGameLogService gameLogService;

    /**
     * 查询游戏日志列表
     */
    @PreAuthorize("@ss.hasPermi('game:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(GameLog gameLog)
    {

        startPage();
        List<GameLog> list = gameLogService.selectGameLogList(gameLog);
        return getDataTable(list);
    }

    /**
     * 导出游戏日志列表
     */
    @PreAuthorize("@ss.hasPermi('game:log:export')")
    @Log(title = "游戏日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameLog gameLog)
    {
        List<GameLog> list = gameLogService.selectGameLogList(gameLog);
        ExcelUtil<GameLog> util = new ExcelUtil<GameLog>(GameLog.class);
        util.exportExcel(response, list, "游戏日志数据");
    }

    /**
     * 获取游戏日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('game:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gameLogService.selectGameLogById(id));
    }

    /**
     * 新增游戏日志
     */
    @PreAuthorize("@ss.hasPermi('game:log:add')")
    @Log(title = "游戏日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameLog gameLog)
    {
        return toAjax(gameLogService.insertGameLog(gameLog));
    }

    /**
     * 修改游戏日志
     */
    @PreAuthorize("@ss.hasPermi('game:log:edit')")
    @Log(title = "游戏日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameLog gameLog)
    {
        return toAjax(gameLogService.updateGameLog(gameLog));
    }

    /**
     * 删除游戏日志
     */
    @PreAuthorize("@ss.hasPermi('game:log:remove')")
    @Log(title = "游戏日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameLogService.deleteGameLogByIds(ids));
    }
}
